package huoye.shops.utils;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.widget.AdapterView;

import com.codeideology.android.utils.ChoosePicDialogUtils;
import com.codeideology.android.widget.ios.dialog.base.ActionSheetDialog;
import com.codeideology.android.widget.ios.dialog.listener.OnOperItemClickL;

import huoye.shops.base.BaseActivity;
import huoye.shops.base.FSApplication;


/**
 * Created by user on 2017/10/12.
 */

public class Utils {

    public static void checkVersion(final BaseActivity activity, final boolean showHit) {

        if (activity == null) {
            return;
        }
        boolean update = ((FSApplication) activity.getApplication()).isUpdate();
        if(!showHit && !update) {
            return;
        }

        if(showHit) {
            activity.showProcessingIndicator();
        } else {
            if (!update) {
                return;
            }
        }


//        UpdateVersionUtil.checkVersion(activity, (APIUrls.API_HOST + APIUrls.CHECK_VERSION_URI), new UpdateVersionUtil.UpdateListener() {
//
//            @Override
//            public void onUpdateReturned(int updateStatus, VersionInfo versionInfo) {
//                if (showHit) {
//                    activity.hideProcessingIndicator();
//                }
//                //判断回调过来的版本检测状态
//                switch (updateStatus) {
//                    case UpdateStatus.YES: {
//                        //弹出更新提示
//                        UpdateVersionUtil.showDialog(activity, versionInfo, new UpdateVersionUtil.OnButtonListener() {
//                            @Override
//                            public void onCancelClick() {
//                                ((FSApplication) activity.getApplication()).setUpdate(false);
//                            }
//                        });
//                        break;
//                    }
//
//                    case UpdateStatus.NO: {
//                        if (showHit) {
//                            //没有新版本
//                            activity.makeToast("已经是最新版本了!");
//                        }
//                        break;
//                    }
//
//
//                    case UpdateStatus.NOWIFI: {
//
//                        UpdateVersionUtil.showDialog(activity, versionInfo, null);
//                        if (showHit) {
//                            //当前是非wifi网络
//                            activity.makeToast("只有在wifi下更新！");
//                        }
//                        break;
//                    }
//                    case UpdateStatus.ERROR: {
//                        if (showHit) {
//                            //检测失败
//                            activity.makeToast("检测失败，请稍后重试！");
//                        }
//                        break;
//                    }
//                    case UpdateStatus.TIMEOUT: {
//                        if (showHit) {
//                            //链接超时
//                            activity.makeToast("链接超时，请检查网络设置!");
//                        }
//                        break;
//                    }
//                }
//            }
//        });
    }

    public static ActionSheetDialog showActionSheetDialog(Context context, String title, String[] stringItems, final OnItemClickListener onOperItemClickL) {

        final ActionSheetDialog dialog = new ActionSheetDialog(context, stringItems, null);
        if (com.codeideology.android.utils.StringUtils.isNotEmpty(title)) {
            dialog.title(title);
        } else {
            dialog.isTitleShow(false);
        }
        dialog.titleTextSize_SP(14.5f)//
                .show();
        dialog.setOnOperItemClickL(new OnOperItemClickL() {
            @Override
            public void onOperItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                onOperItemClickL.onOperItemClick(adapterView, view, i, l);
                dialog.dismiss();
            }
        });
        return dialog;
    }

    public static ActionSheetDialog showChoosePicDialog(final Activity context, String title, final ChoosePicDialogUtils.OnChoosePicListener onChoosePicListener) {
        String[] items = new String[]{"选择本地照片", "拍照"};
        final ActionSheetDialog dialog = new ActionSheetDialog(context, items, (View) null);
        if (com.codeideology.android.utils.StringUtils.isNotEmpty(title)) {
            dialog.title(title);
        } else {
            dialog.isTitleShow(false);
        }

        dialog.titleTextSize_SP(14.5F).show();
        dialog.setOnOperItemClickL(new OnOperItemClickL() {
            public void onOperItemClick(AdapterView<?> adapterView, View view, int position, long l) {
                switch (position) {
                    case 0:
                        onChoosePicListener.onChoosePicture();
                        break;
                    case 1:
                        onChoosePicListener.onTakePicture();
                }

                dialog.dismiss();
            }
        });
        return dialog;
    }


    public interface OnItemClickListener {
        void onOperItemClick(AdapterView<?> var1, View var2, int var3, long var4);
    }

}
